<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>确认小组</title>
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../js/jquery.js"></script>
    <script src="../js/myAjax.js"></script>
    <script src="../js/util/popup.js"></script>
</head>
<body>
<div style="margin-left: 50px; margin-top: 120px">
    <div class="layui-form-item">
        <label class="layui-form-label">选择小组</label>
        <div class="layui-input-block">
            <select name="team" lay-verify="required" id="teamList">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户权限</label>
        <div class="layui-input-inline">
            <input type="text" name="title" required lay-verify="required" id="user-name" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请输入您的用户名</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="getAccess()">获取权限</button>
            <button type="reset" onclick="resetEdit('/html/confirmTeam.html')" class="layui-btn layui-btn-primary">
                点击重置
            </button>
        </div>
    </div>
</div>
<script>
    //给小组下拉框赋值，
    findTeam();

    function findTeam() {
        let result = myAjax('/group/selectAll', 'post', {});
        let html = " <option value='0'>全部</option>";
        for (let i = 0; i < result.list.length; i++) {
            html += ' <option value="' + result.list[i].id + '">' + result.list[i].name + '</option>';
        }
        $("#teamList").html(html);
    }
 layui.use("layer");
    //得到数据去后台查询
    function getAccess() {
        let data = {
            name: $("#teamList").find("option:selected").text(),
            leader: $("#user-name").val(),
        }
        //后台验证权限，如果合法，返回小组id，然后直接打开点到界面
        let result = myAjax('/group/confirm', 'get', data);

        if (result != null) {
            console.log(result.id);
            sessionStorage.setItem("add-teamId", result.id);
            parent.layer.closeAll();
            parent.layer.open({
                type: 2,
                anim: 3,
                title: '进行点到',
                area: ['600px', '500px'],
                shadeClose: true, //点击遮罩关闭
                content: ['/html/signInAdd.html', 'no'],
            })
        } else {
            layer.msg("抱歉！您暂无此权限");
        }
    }
</script>
</body>
</html>